﻿#region Copyright & License
//
// Copyright 2010 sd&c Hofmann 
// 
// mailto:info@sdch.de
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.UserCode;
using log4net;
using SDCH.SharePoint.Log4Sandbox.UserCode.ProxyOperationArgs;
using System.Reflection;
using Microsoft.Office.Server.Diagnostics;

namespace SDCH.SharePoint.Log4Sandbox.TrustedProxy
{
    public class LogOperation :SPProxyOperation
    {
        public override object Execute(SPProxyOperationArgs args)
        {
            try
            {
                LogArgs logArgs = (LogArgs)args;
                ILog log = LogManager.GetLogger(logArgs.Repository, logArgs.Logger);
                MethodInfo method = log.GetType().GetMethod(logArgs.Method, BindingFlags.Instance | BindingFlags.Public, null, logArgs.ParameterTypes, null);
                method.Invoke(log, logArgs.Parameters);
                return true;
            
            }
            catch (Exception ex) {
                PortalLog.LogString("{0} :: {1}", ex.Message, ex.StackTrace); 
            }

            return null;
        }


    }
}
